package cn.fl.customer.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.customer.service.ICstAssInfoService;
import cn.fl.customer.transform.CstAssInfoVOTransform;
import cn.fl.customer.vo.CstAssInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.system.constant.SysLogConstant;
import fl.customer.facade.customer.condition.CstAssInfoQueryCondition;
import fl.customer.facade.customer.constant.CustomerConstant;
import fl.customer.facade.customer.dto.CstAssInfoDTO;

/**
 * @Description: 客户资产信息表 控制层
 */
@Controller
@RequestMapping("/customer/cstassinfo")
public class CstAssInfoController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(CstAssInfoController.class);

	/**
	 * CstAssInfo 服务层BEAN
	 */
	@Autowired
	private ICstAssInfoService cstAssIfnoService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.info(logger, "toListPage", "跳转到客户资产信息列表页面.", CurrentThreadContext.getCurrentUserName());
		ModelAndView view = new ModelAndView("customer/cstassifno/list");
		return view;
	}
	/**
	 * 到车辆资产详情页面
	 */
	@RequestMapping(value = "/toCarDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toCarDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String caiId = request.getParameter("caiId");
		ModelAndView view = new ModelAndView("customer/cstassinfo/custCstassInfoCarDetail");
		view.addObject("caiId", caiId);
		BaseLogUtils.info(logger, "toCarDetailPage", "跳转到车辆资产详情页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到新增修改车辆资产页面
	 */
	@RequestMapping(value = "/toCarAddPage.do", method = { RequestMethod.GET })
	public ModelAndView toCarAddPage(HttpServletRequest request, HttpServletResponse response) {
		String cstId = request.getParameter("cstId");
		String caiId = request.getParameter("caiId");
		ModelAndView view = new ModelAndView("customer/cstassinfo/custCstassInfoCarAdd");
		view.addObject("cstId", cstId);
		view.addObject("caiId", caiId);//修改时使用的关联关系ID
		BaseLogUtils.info(logger, "toCarAddPage", "跳转到新增修改车辆资产页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	

	/**
	 * 初始化车辆资产列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initCarList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initCarList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String cstId = request.getParameter("cstId");
		if(StringUtils.isEmpty(cstId)){
			ListPageVO<CstAssInfoVO> listPage = new ListPageVO<CstAssInfoVO>(new ArrayList<CstAssInfoVO>(), 0);
			return listPage;
		}
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		CstAssInfoQueryCondition qc = new CstAssInfoQueryCondition();
		List<Long> cstIdList = new ArrayList<>();
		cstIdList.add(Long.valueOf(cstId));
		qc.setAssPropCd(CustomerConstant.CST_ASS_INFO_EQU_CD);
		qc.setCstIdList(cstIdList);
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		page.setCondition(qc);
		//page.setEveryPage(Integer.MAX_VALUE);//最大数据量
		Pager pager = this.cstAssIfnoService.searchListPage(page);
		List<CstAssInfoDTO> list = (List<CstAssInfoDTO>) pager.getResultList();
		List<CstAssInfoVO> voList = CstAssInfoVOTransform.toVOList(list);
		ListPageVO<CstAssInfoVO> listPage = new ListPageVO<CstAssInfoVO>(voList, pager.getTotalCount());
		BaseLogUtils.info(logger, "initCarList", "初始化车辆资产页面数据.DATA:"+ JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 删除车辆资产数据
	 */
	@RequestMapping(value = "/removeCarById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeCarById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "removeCarById", "数据主键不存在!", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			List<Long> idList = new ArrayList<>();
			idList.add(Long.valueOf(id));
			this.cstAssIfnoService.removeByIds(idList);
			BaseLogUtils.info(logger, "removeCarById", "删除车辆资产数据成功.ID:"+id, CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeCarById", "删除车辆资产数据失败!ID:" + id + "-ERROR:"+ ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeCarById", "删除车辆资产数据,系统错误!ID:" + id + "-ERROR:"+ ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 得到一条车辆资产信息记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getCarById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getCarById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "getCarById", "获取车辆资产数据主键参数不存在.", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			CstAssInfoVO vo = this.cstAssIfnoService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getCarById", "获取车辆资产数据不存在.ID:" + id, CurrentThreadContext.getCurrentUserName());
			}else{
				BaseLogUtils.info(logger, "getCarById", "获取车辆资产数据成功.ID:" + id, CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getCarById", "获取车辆资产数据失败.ID:" + id + "-ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getCarById", "获取车辆资产数据,系统错误.ID:" + id + "-ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增车辆资产信息
	 */
	@RequestMapping(value = "/addCar.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addCar(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		CstAssInfoVO entity = this.getRequestParamsForCar(request);
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
			entity.setIsDel(BaseConstant.IS_YESNO_NO);
			entity.setCrtTm(new Date());
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			Long id = this.cstAssIfnoService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "addCar", "新增车辆信息成功,ID:"+id+".DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "addCar", "新增车辆信息失败！DATA:" + JSONObject.toJSONString(entity) + " ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addCar", "新增车辆信息,系统错误！DATA:" + JSONObject.toJSONString(entity) + " ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}
	
	/**
	 * 修改车辆资产信息
	 */
	@RequestMapping(value = "/modifyCar.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyCar(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		CstAssInfoVO entity = this.getRequestParamsForCar(request);
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modifyCar", "修改车辆信息主键不存在！.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			entity.setId(Long.valueOf(id));
			entity.setMdfTm(new Date());
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			boolean success = this.cstAssIfnoService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
				BaseLogUtils.info(logger, "modifyCar", "修改车辆信息失败,ID:"+id+".DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}else{
				BaseLogUtils.info(logger, "modifyCar", "修改车辆信息成功,ID:"+id+".DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
			BaseLogUtils.info(logger, "modifyCar", "修改车辆信息失败,ID:"+id+".DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modifyCar", "修改车辆信息,系统错误！ID:"+id+".DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
		
	}
	
	//**********************************土地房产信息*******************************//
	
	/**
	 * 到土地房产资产详情页面
	 */
	@RequestMapping(value = "/toLandPropertyDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toLandPropertyDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String caiId = request.getParameter("caiId");
		ModelAndView view = new ModelAndView("customer/cstassinfo/custCstassInfoLandPropertyDetail");
		view.addObject("caiId", caiId);
		BaseLogUtils.info(logger, "toLandPropertyDetailPage", "跳转到土地房产资产详情页面！", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到新增修改土地房产资产页面
	 */
	@RequestMapping(value = "/toLandPropertyAddPage.do", method = { RequestMethod.GET })
	public ModelAndView toLandPropertyAddPage(HttpServletRequest request, HttpServletResponse response) {
		String cstId = request.getParameter("cstId");
		String caiId = request.getParameter("caiId");
		ModelAndView view = new ModelAndView("customer/cstassinfo/custCstassInfoLandPropertyAdd");
		view.addObject("cstId", cstId);
		view.addObject("caiId", caiId);//修改时使用的关联关系ID
		BaseLogUtils.info(logger, "toLandPropertyAddPage", "跳转到新增/修改土地房产资产页面！", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	
	/**
	 * 初始化土地房产资产列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initLandPropertyList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initLandPropertyList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String cstId = request.getParameter("cstId");
		if(StringUtils.isEmpty(cstId)){
			ListPageVO<CstAssInfoVO> listPage = new ListPageVO<CstAssInfoVO>(new ArrayList<CstAssInfoVO>(), 0);
			BaseLogUtils.info(logger, "initLandPropertyList", "客户ID不存在直接返回空集合！", CurrentThreadContext.getCurrentUserName());
			return listPage;
		}
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		CstAssInfoQueryCondition qc = new CstAssInfoQueryCondition();
		List<Long> cstIdList = new ArrayList<>();
		cstIdList.add(Long.valueOf(cstId));
		qc.setAssPropCd(CustomerConstant.CST_ASS_INFO_LAND_PROP_CD);
		qc.setCstIdList(cstIdList);
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		page.setCondition(qc);
		//page.setEveryPage(Integer.MAX_VALUE);//最大数据量
		Pager pager = this.cstAssIfnoService.searchListPage(page);
		List<CstAssInfoDTO> list = (List<CstAssInfoDTO>) pager.getResultList();
		List<CstAssInfoVO> voList = CstAssInfoVOTransform.toVOList(list);
		ListPageVO<CstAssInfoVO> listPage = new ListPageVO<CstAssInfoVO>(voList, pager.getTotalCount());
		BaseLogUtils.info(logger, "initLandPropertyList", "初始化土地房产信息！cstId:"+cstId+"-DATA:"+JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 删除土地房产资产数据
	 */
	@RequestMapping(value = "/removeLandPropertyById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeLandPropertyById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "removeLandPropertyById", "删除土地房产ID参数不存在！id:"+id, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			List<Long> idList = new ArrayList<>();
			idList.add(Long.valueOf(id));
			this.cstAssIfnoService.removeByIds(idList);
			BaseLogUtils.info(logger, "removeLandPropertyById", "删除成功！id:"+id, CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeLandPropertyById", "删除失败！id:"+id + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeLandPropertyById", "删除失败！id:"+id + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		
		return result;
	}
	
	/**
	 * 得到一条土地房产资产信息记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getLandPropertyById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getLandPropertyById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "getLandPropertyById", "主键不能为空！id:"+id, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			CstAssInfoVO vo = this.cstAssIfnoService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getLandPropertyById", "获取数据不存在！id:"+id, CurrentThreadContext.getCurrentUserName());
			}else{
				BaseLogUtils.info(logger, "getLandPropertyById", "获取数据成功！id:"+id, CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getLandPropertyById", "获取数据失败！id:"+id + "-ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getLandPropertyById", "获取数据失败！id:"+id + "-ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 新增土地房产信息
	 */
	@RequestMapping(value = "/addLandProperty.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addLandProperty(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		CstAssInfoVO entity = this.getRequestParamsForLandProperty(request);
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
			entity.setIsDel(BaseConstant.IS_YESNO_NO);
			entity.setCrtTm(new Date());
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			Long id = this.cstAssIfnoService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "addLandProperty", "新增成功！id:"+id + "-DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "addLandProperty", "新增失败！DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addLandProperty", "新增失败！DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		
		return result;
	}
	
	/**
	 * 修改土地房产资产信息
	 */
	@RequestMapping(value = "/modifyLandProperty.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyLandProperty(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		CstAssInfoVO entity = this.getRequestParamsForLandProperty(request);
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modifyLandProperty", "主键参数不存在！" + "-DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			entity.setId(Long.valueOf(id));
			entity.setMdfTm(new Date());
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			boolean success = this.cstAssIfnoService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
				BaseLogUtils.info(logger, "modifyLandProperty", "修改失败！ID:" + id + "-DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}else{
				BaseLogUtils.info(logger, "modifyLandProperty", "修改成功！ID:" + id + "-DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modifyLandProperty", "修改失败！ID:" + id + "-DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modifyLandProperty", "修改失败！ID:" + id + "-DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
		
	}
	//**********************************其他资产信息*******************************//
	
	/**
	 * 到其他资产详情页面
	 */
	@RequestMapping(value = "/toOtherDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toOtherDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String caiId = request.getParameter("caiId");
		ModelAndView view = new ModelAndView("customer/cstassinfo/custCstassInfoOtherDetail");
		view.addObject("caiId", caiId);
		BaseLogUtils.info(logger, "toOtherDetailPage", "跳转到其它资产详情页面", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到新增修改其他资产页面
	 */
	@RequestMapping(value = "/toOtherAddPage.do", method = { RequestMethod.GET })
	public ModelAndView toOtherAddPage(HttpServletRequest request, HttpServletResponse response) {
		String cstId = request.getParameter("cstId");
		String caiId = request.getParameter("caiId");
		ModelAndView view = new ModelAndView("customer/cstassinfo/custCstassInfoOtherAdd");
		view.addObject("cstId", cstId);
		view.addObject("caiId", caiId);//修改时使用的关联关系ID
		BaseLogUtils.info(logger, "toOtherAddPage", "跳转到其它资产新增页面", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	
	/**
	 * 初始化其他资产列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initOtherList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initOtherList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String cstId = request.getParameter("cstId");
		if(StringUtils.isEmpty(cstId)){
			ListPageVO<CstAssInfoVO> listPage = new ListPageVO<CstAssInfoVO>(new ArrayList<CstAssInfoVO>(), 0);
			BaseLogUtils.info(logger, "initOtherList", "初始化其它资产列表客户ID不存在,直接返回空集合！", CurrentThreadContext.getCurrentUserName());
			return listPage;
		}
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		CstAssInfoQueryCondition qc = new CstAssInfoQueryCondition();
		List<Long> cstIdList = new ArrayList<>();
		cstIdList.add(Long.valueOf(cstId));
		qc.setAssPropCd(CustomerConstant.CST_ASS_INFO_OTH_CD);
		qc.setCstIdList(cstIdList);
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		page.setCondition(qc);
		//page.setEveryPage(Integer.MAX_VALUE);//最大数据量
		Pager pager = this.cstAssIfnoService.searchListPage(page);
		List<CstAssInfoDTO> list = (List<CstAssInfoDTO>) pager.getResultList();
		List<CstAssInfoVO> voList = CstAssInfoVOTransform.toVOList(list);
		ListPageVO<CstAssInfoVO> listPage = new ListPageVO<CstAssInfoVO>(voList, pager.getTotalCount());
		BaseLogUtils.info(logger, "initOtherList", "初始化其它资产列表！" + "-DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 删除其他资产数据
	 */
	@RequestMapping(value = "/removeOtherById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeOtherById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "removeOtherById", "主键不存在！", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			List<Long> idList = new ArrayList<>();
			idList.add(Long.valueOf(id));
			this.cstAssIfnoService.removeByIds(idList);
			BaseLogUtils.info(logger, "removeOtherById", "删除成功！ID:" + id, CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeOtherById", "删除失败！ID:" + id + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeOtherById", "删除失败！ID:" + id + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		
		return result;
	}
	
	/**
	 * 得到一条其他资产信息记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getOtherById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getOtherById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "getOtherById", "主键不存在！", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			CstAssInfoVO vo = this.cstAssIfnoService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getOtherById", "获取数据不存在！ID:" + id, CurrentThreadContext.getCurrentUserName());
			}else{
				BaseLogUtils.info(logger, "getOtherById", "获取数据失败,返回对象为null,ID:" + id, CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getOtherById", "获取数据失败,ID:" + id + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getOtherById", "获取数据失败,ID:" + id + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 新增其他资产信息
	 */
	@RequestMapping(value = "/addOther.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object addOther(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		CstAssInfoVO entity = this.getRequestParamsForOther(request);
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
			entity.setIsDel(BaseConstant.IS_YESNO_NO);
			entity.setCrtTm(new Date());
			entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			Long id = this.cstAssIfnoService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "addOther", "新增成功！ ID:" + id + "-DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error(ex.getMessage(), ex);
			BaseLogUtils.info(logger, "addOther", "新增失败！" + "-DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addOther", "新增失败！" + "-DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		
		return result;
	}
	
	/**
	 * 修改其他资产信息
	 */
	@RequestMapping(value = "/modifyOther.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyOther(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		CstAssInfoVO entity = this.getRequestParamsForOther(request);
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modifyOther", "主键不存在！", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			entity.setId(Long.valueOf(id));
			entity.setMdfTm(new Date());
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			boolean success = this.cstAssIfnoService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
				BaseLogUtils.info(logger, "modifyOther", "修改失败！ ID:" + id + "-DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}else{
				BaseLogUtils.info(logger, "modifyOther", "修改成功！ ID:" + id + "-DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modifyOther", "修改失败！ ID:" + id + "-DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modifyOther", "修改失败！ ID:" + id + "-DATA:" + JSONObject.toJSONString(entity) + "-ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
		
	}
	
	
	//***********************************私有方法***************************//
	/**
	 * 获取车辆资产新增修改参数
	 */
	private CstAssInfoVO getRequestParamsForCar(HttpServletRequest request) {
		String cstId = request.getParameter("cstId");//客户id
		String assNm = request.getParameter("assNm");//设备名称
		String brCd = request.getParameter("brCd");//品牌
		String prdMdl = request.getParameter("prdMdl");//型号
		String assOwner = request.getParameter("assOwner");//所有权人
		String value = request.getParameter("value");//市值(元)
		String qty = request.getParameter("qty");//数量
		String revenue = request.getParameter("revenue");//收益(元)
		String purchDt = request.getParameter("purchDt");//购买时间
		String assRem = request.getParameter("assRem");//备注
		
		
		if(StringUtils.isNotEmpty(value)&& !StringUtils.isNumeric(value)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "市值项仅支持数字");
		}
		if(StringUtils.isNotEmpty(qty)&& !StringUtils.isNumeric(qty)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "数量项仅支持数字");
		}
		if(StringUtils.isNotEmpty(revenue)&& !StringUtils.isNumeric(revenue)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "收益项仅支持数字");
		}
		
		
		CstAssInfoVO entity = new CstAssInfoVO();
		entity.setAssPropCd(CustomerConstant.CST_ASS_INFO_EQU_CD);
		entity.setCstId(Long.valueOf(cstId));
		entity.setBrCd(brCd);
		entity.setPrdMdl(prdMdl);
		entity.setAssOwner(assOwner);
		entity.setAssNm(assNm);
		if(StringUtils.isNotBlank(qty)){
			
			entity.setQty(Long.valueOf(qty));
		}
		if(StringUtils.isNotBlank(value)){
			
			entity.setValue(Long.valueOf(value));
		}
		if(StringUtils.isNotBlank(revenue)){
			
			entity.setRevenue(Long.valueOf(revenue));
		}
		entity.setAssRem(assRem);
		if(StringUtils.isNotBlank(purchDt)){
			entity.setPurchDt(DateUtils.formatStringToDate(purchDt, DateUtils.YYYY_MM_DD));
		}
		
		return entity;
	}
	/**
	 * 获取土地房产资产新增修改参数
	 */
	private CstAssInfoVO getRequestParamsForLandProperty(HttpServletRequest request) {
		String cstId = request.getParameter("cstId");//客户id
		String area = request.getParameter("area");//面积
		String addr = request.getParameter("addr");//地址
		String assOwner = request.getParameter("assOwner");//所有权人
		String value = request.getParameter("value");//市值(元)
		String revenue = request.getParameter("revenue");//收益(元)
		String purchDt = request.getParameter("purchDt");//购买时间
		String assRem = request.getParameter("assRem");//备注
		
		
		if(StringUtils.isNotEmpty(value)&& !StringUtils.isNumeric(value)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "市值项仅支持数字");
		}
		if(StringUtils.isNotEmpty(area)&& !StringUtils.isNumeric(area)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "数量项仅支持数字");
		}
		if(StringUtils.isNotEmpty(revenue)&& !StringUtils.isNumeric(revenue)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "收益项仅支持数字");
		}
		
		
		CstAssInfoVO entity = new CstAssInfoVO();
		entity.setAssPropCd(CustomerConstant.CST_ASS_INFO_LAND_PROP_CD);
		entity.setCstId(Long.valueOf(cstId));
		entity.setAssOwner(assOwner);
		entity.setAddr(addr);
		if(StringUtils.isNotBlank(area)){
			
			entity.setArea(Long.valueOf(area));
		}
		if(StringUtils.isNotBlank(value)){
			
			entity.setValue(Long.valueOf(value));
		}
		if(StringUtils.isNotBlank(revenue)){
			
			entity.setRevenue(Long.valueOf(revenue));
		}
		entity.setAssRem(assRem);
		if(StringUtils.isNotBlank(purchDt)){
			entity.setPurchDt(DateUtils.formatStringToDate(purchDt, DateUtils.YYYY_MM_DD));
		}
		
		return entity;
	}
	/**
	 * 获取其他资产新增修改参数
	 */
	private CstAssInfoVO getRequestParamsForOther(HttpServletRequest request) {
		String cstId = request.getParameter("cstId");//客户id
		String assNm = request.getParameter("assNm");//资产名称
		String assOwner = request.getParameter("assOwner");//所有权人
		String value = request.getParameter("value");//市值(元)
		String revenue = request.getParameter("revenue");//收益(元)
		String purchDt = request.getParameter("purchDt");//购买时间
		String assRem = request.getParameter("assRem");//备注
		
		
		if(StringUtils.isNotEmpty(value)&& !StringUtils.isNumeric(value)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "市值项仅支持数字");
		}
		if(StringUtils.isNotEmpty(revenue)&& !StringUtils.isNumeric(revenue)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "收益项仅支持数字");
		}
		
		
		CstAssInfoVO entity = new CstAssInfoVO();
		entity.setAssPropCd(CustomerConstant.CST_ASS_INFO_OTH_CD);
		entity.setCstId(Long.valueOf(cstId));
		entity.setAssOwner(assOwner);
		entity.setAssNm(assNm);
		if(StringUtils.isNotBlank(value)){
			
			entity.setValue(Long.valueOf(value));
		}
		if(StringUtils.isNotBlank(revenue)){
			
			entity.setRevenue(Long.valueOf(revenue));
		}
		entity.setAssRem(assRem);
		if(StringUtils.isNotBlank(purchDt)){
			entity.setPurchDt(DateUtils.formatStringToDate(purchDt, DateUtils.YYYY_MM_DD));
		}
		
		return entity;
	}
}

